log using S1_S9_and_S19.smcl,replace
use  NER_panel_data.dta, clear
gen country=1
append using NIGERIA_panel_data.dta
replace country=2 if country ==.

append using ETHIOPIA_panel_data.dta
replace country=3 if country ==.

append using UGA_panel_data.dta
replace country=4 if country ==.

append using TZA_panel_data.dta
replace country=5 if country ==.

append using MWI_panel_data.dta
replace country=6 if country ==.

xtset HHID_panel year

label define country 1 "Niger" 2 "Nigeria" 3 "Ethiopia" 4 "Uganda" 5 "Tanzania" 6 "Malawi"
label values country country



foreach x of varlist hhsize dependent_share head_age female_head head_read  motobike phone  electricity wagejob enterprise weather_shock  plot_area other_crop hdd9 pdd9 no_species{
egen `x'_mean=mean(`x'), by(HHID_panel)
}
tab year, generate(year_)
global year_NIGER year_4
global year_NIGERIA year_3 year_5 year_8
global year_ETHIOPIA year_6
global year_UGANDA   year_3 year_4 year_6 year_8 year_10
global year_TANZANIA year_1 year_5 year_7
global year_MALAWI year_3 year_6 
global xlist hhsize dependent_share head_age female_head head_read  motobike phone  electricity wagejob enterprise weather_shock  plot_area other_crop  motobike_mean phone_mean electricity_mean wagejob_mean enterprise_mean  




********************************************************************************
*                              Table S1                                        *
********************************************************************************
eststo clear
xtreg hdd9  no_species   $xlist  no_species_mean i.country i.year  , cluster(HHID_panel) 
eststo est1


xtreg hdd9  no_species   $xlist  no_species_mean $year_ETHIOPIA if country==3, cluster(HHID_panel) 
eststo est2

xtreg hdd9  no_species   $xlist  no_species_mean $year_MALAWI if country==6, cluster(HHID_panel) 
eststo est3


xtreg hdd9  no_species   $xlist  no_species_mean $year_NIGER if country==1, cluster(HHID_panel) 
eststo est4


xtreg hdd9  no_species   $xlist  no_species_mean $year_NIGERIA if country==2, cluster(HHID_panel) 
eststo est5


xtreg hdd9  no_species   $xlist  no_species_mean $year_TANZANIA if country==5, cluster(HHID_panel) 
eststo est6

xtreg hdd9  no_species   $xlist  no_species_mean  $year_UGANDA if country==4, cluster(HHID_panel) 
eststo est7

esttab using  S1.rtf, se replace star(* 0.1 ** 0.05 *** 0.01) cells (b(star fmt(%9.3f)) se (par(( )) fmt(%9.3f)))  stats(N r2_b  r2_w r2_o p, fmt(%4.0f %4.3f %4.3f %6.3f)) keep(no_species   $xlist  no_species_mean _cons)



********************************************************************************
*                              Table S2                                        *
********************************************************************************
eststo clear

xtreg hdd9  pdd9   $xlist   pdd9_mean i.country i.year, cluster(HHID_panel) 
eststo est1


xtreg hdd9  pdd9   $xlist  pdd9_mean $year_ETHIOPIA if country==3, cluster(HHID_panel) 
eststo est2

xtreg hdd9  pdd9   $xlist  pdd9_mean $year_MALAWI if country==6, cluster(HHID_panel) 
eststo est3


xtreg hdd9  pdd9   $xlist  pdd9_mean $year_NIGER if country==1, cluster(HHID_panel) 
eststo est4


xtreg hdd9  pdd9   $xlist  pdd9_mean $year_NIGERIA if country==2, cluster(HHID_panel) 
eststo est5


xtreg hdd9  pdd9   $xlist  pdd9_mean $year_TANZANIA if country==5, cluster(HHID_panel) 
eststo est6

xtreg hdd9  pdd9   $xlist  pdd9_mean  $year_UGANDA if country==4, cluster(HHID_panel) 
eststo est7
esttab using  S2.rtf, se replace star(* 0.1 ** 0.05 *** 0.01) cells (b(star fmt(%9.3f)) se (par(( )) fmt(%9.3f)))  stats(N r2_b  r2_w r2_o p, fmt(%4.0f %4.3f %4.3f %6.3f)) keep(pdd9   $xlist  pdd9_mean _cons)




********************************************************************************
*                             Table S3                                         *
********************************************************************************
preserve
drop if dist_popcenter==.

drop pdd9_mean  no_species_mean hhsize_mean dependent_share_mean head_age_mean female_head_mean head_read_mean motobike_mean phone_mean electricity_mean wagejob_mean enterprise_mean weather_shock_mean plot_area_mean other_crop_mean
egen pdd9_mean=mean(pdd9), by(HHID_panel)
egen pdd9_mean_vill=mean(pdd9_vill), by(HHID_panel)
egen pdd9_mean_town=mean(pdd9_town), by(HHID_panel)
egen pdd9_mean_dist=mean(pdd9_dist), by(HHID_panel)

foreach x of varlist hhsize dependent_share head_age female_head head_read  motobike phone  electricity wagejob enterprise weather_shock  plot_area other_crop{
egen `x'_mean=mean(`x'), by(HHID_panel)
}


eststo clear
xtreg hdd9  c.pdd9##c.dist_popcenter   $xlist  pdd9_mean  i.country i.year  , cluster(HHID_panel) 
eststo est1


xtreg hdd9  c.pdd9##c.dist_popcenter   $xlist  pdd9_mean  year_6 if country==3, cluster(HHID_panel) 
eststo est2


xtreg hdd9  c.pdd9##c.dist_popcenter   $xlist  pdd9_mean year_3  if country==6, cluster(HHID_panel) 
eststo est3

 
xtreg hdd9  c.pdd9##c.dist_popcenter    $xlist  pdd9_mean  year_4 if country==1, cluster(HHID_panel) 
eststo est4


xtreg hdd9  c.pdd9##c.dist_popcenter    $xlist  pdd9_mean  year_3 year_5 year_8 if country==2, cluster(HHID_panel) 
eststo est5


xtreg hdd9  c.pdd9##c.dist_popcenter   $xlist  pdd9_mean year_1 year_3  if country==5, cluster(HHID_panel) 
eststo est6

xtreg hdd9  c.pdd9##c.dist_popcenter   $xlist  pdd9_mean  year_2 year_3  if country==4, cluster(HHID_panel) 
eststo est7
esttab using  S3.rtf, se replace star(* 0.1 ** 0.05 *** 0.01) cells (b(star fmt(%9.3f)) se (par(( )) fmt(%9.3f)))  stats(N r2_b  r2_w r2_o p, fmt(%4.0f %4.3f %4.3f %6.3f)) keep( pdd9 c.pdd9#c.dist_popcenter dist_popcenter $xlist  pdd9_mean _cons)
restore






********************************************************************************  
*                               Table S4                                       *
********************************************************************************
preserve
eststo clear
drop if hdd9_own==.|hdd9_purchase==.
drop  pdd9_mean no_species_mean hhsize_mean dependent_share_mean head_age_mean female_head_mean head_read_mean motobike_mean phone_mean electricity_mean wagejob_mean enterprise_mean weather_shock_mean plot_area_mean other_crop_mean
foreach x of varlist pdd9 hhsize dependent_share head_age female_head head_read  motobike phone  electricity wagejob enterprise weather_shock  plot_area other_crop{
egen `x'_mean=mean(`x'), by(HHID_panel)
}

eststo clear
xtreg hdd9_own  pdd9   $xlist  pdd9_mean i.country i.year  , cluster(HHID_panel) 
eststo est1


xtreg hdd9_own  pdd9   $xlist  pdd9_mean $year_ETHIOPIA if country==3, cluster(HHID_panel) 
eststo est2

xtreg hdd9_own  pdd9   $xlist  pdd9_mean $year_MALAWI if country==6, cluster(HHID_panel) 
eststo est3

xtreg hdd9_own  pdd9   $xlist  pdd9_mean $year_NIGER if country==1, cluster(HHID_panel) 
eststo est4


xtreg hdd9_own  pdd9   $xlist  pdd9_mean $year_NIGERIA if country==2, cluster(HHID_panel) 
eststo est5


xtreg hdd9_own  pdd9   $xlist  pdd9_mean $year_TANZANIA if country==5, cluster(HHID_panel) 
eststo est6


xtreg hdd9_own  pdd9   $xlist  pdd9_mean  $year_UGANDA if country==4, cluster(HHID_panel) 
eststo est7
esttab using  S4.rtf, se replace star(* 0.1 ** 0.05 *** 0.01) cells (b(star fmt(%9.3f)) se (par(( )) fmt(%9.3f)))  stats(N r2_b  r2_w r2_o p, fmt(%4.0f %4.3f %4.3f %6.3f)) keep(pdd9   $xlist  pdd9_mean _cons)





********************************************************************************  
*                               Table S5                                       *
********************************************************************************
eststo clear
xtreg hdd9_purchase  pdd9   $xlist  pdd9_mean i.country i.year  , cluster(HHID_panel) 
eststo est1


xtreg hdd9_purchase  pdd9   $xlist  pdd9_mean $year_ETHIOPIA if country==3, cluster(HHID_panel) 
eststo est2

xtreg hdd9_purchase  pdd9   $xlist  pdd9_mean $year_MALAWI if country==6, cluster(HHID_panel) 
eststo est3

xtreg hdd9_purchase  pdd9   $xlist  pdd9_mean $year_NIGER if country==1, cluster(HHID_panel) 
eststo est4


xtreg hdd9_purchase  pdd9   $xlist  pdd9_mean $year_NIGERIA if country==2, cluster(HHID_panel) 
eststo est5


xtreg hdd9_purchase  pdd9   $xlist  pdd9_mean $year_TANZANIA if country==5, cluster(HHID_panel) 
eststo est6


xtreg hdd9_purchase  pdd9   $xlist  pdd9_mean  $year_UGANDA if country==4, cluster(HHID_panel) 
eststo est7

esttab using  S5.rtf, se replace star(* 0.1 ** 0.05 *** 0.01) cells (b(star fmt(%9.3f)) se (par(( )) fmt(%9.3f)))  stats(N r2_b  r2_w r2_o p, fmt(%4.0f %4.3f %4.3f %6.3f)) keep(pdd9   $xlist  pdd9_mean _cons)
restore





********************************************************************************
*                                Table S6                                      *
********************************************************************************
preserve
drop if sum_vill<=1|sum_vill==.

drop pdd9_mean no_species_mean hhsize_mean dependent_share_mean head_age_mean female_head_mean head_read_mean motobike_mean phone_mean electricity_mean wagejob_mean enterprise_mean weather_shock_mean plot_area_mean other_crop_mean
egen pdd9_mean=mean(pdd9), by(HHID_panel)
egen pdd9_mean_vill=mean(pdd9_vill), by(HHID_panel)
egen pdd9_mean_town=mean(pdd9_town), by(HHID_panel)
egen pdd9_mean_dist=mean(pdd9_dist), by(HHID_panel)

foreach x of varlist hhsize dependent_share head_age female_head head_read  motobike phone  electricity wagejob enterprise weather_shock  plot_area other_crop{
egen `x'_mean=mean(`x'), by(HHID_panel)
}


*                                  hh_level                                    *
eststo clear
xtreg hdd9  pdd9   $xlist  pdd9_mean i.country i.year  , cluster(HHID_panel) 
eststo est1

xtreg hdd9  pdd9   $xlist  pdd9_mean $year_ETHIOPIA if country==3, cluster(HHID_panel) 
eststo est2

xtreg hdd9  pdd9   $xlist  pdd9_mean $year_MALAWI if country==6, cluster(HHID_panel) 
eststo est3


xtreg hdd9  pdd9   $xlist  pdd9_mean $year_NIGER if country==1, cluster(HHID_panel) 
eststo est4


xtreg hdd9  pdd9   $xlist  pdd9_mean $year_NIGERIA if country==2, cluster(HHID_panel) 
eststo est5


xtreg hdd9  pdd9   $xlist  pdd9_mean $year_TANZANIA if country==5, cluster(HHID_panel) 
eststo est6


xtreg hdd9  pdd9   $xlist  pdd9_mean  $year_UGANDA if country==4, cluster(HHID_panel) 
eststo est7
esttab using  S6.rtf, se replace star(* 0.1 ** 0.05 *** 0.01) cells (b(star fmt(%9.3f)) se (par(( )) fmt(%9.3f)))  stats(N r2_b  r2_w r2_o p, fmt(%4.0f %4.3f %4.3f %6.3f)) keep(pdd9   $xlist  pdd9_mean _cons )


********************************************************************************
*                                Table S7                                      *
********************************************************************************
eststo clear
xtreg hdd9  pdd9_vill sum_vill  $xlist  pdd9_mean_vill i.country i.year   , cluster(HHID_panel) 
eststo est1

xtreg hdd9  pdd9_vill sum_vill  $xlist  pdd9_mean_vill $year_ETHIOPIA if country==3, cluster(HHID_panel) 
eststo est2

xtreg hdd9  pdd9_vill sum_vill  $xlist  pdd9_mean_vill $year_MALAWI  if country==6, cluster(HHID_panel) 
eststo est3

xtreg hdd9  pdd9_vill sum_vill  $xlist  pdd9_mean_vill $year_NIGER if country==1, cluster(HHID_panel) 
eststo est4


xtreg hdd9  pdd9_vill sum_vill  $xlist  pdd9_mean_vill $year_NIGERIA if country==2, cluster(HHID_panel) 
eststo est5


xtreg hdd9  pdd9_vill sum_vill  $xlist  pdd9_mean_vill $year_TANZANIA if country==5, cluster(HHID_panel) 
eststo est6


xtreg hdd9  pdd9_vill sum_vill  $xlist  pdd9_mean_vill $year_UGANDA if country==4, cluster(HHID_panel) 
eststo est7
esttab using  S7.rtf, se replace star(* 0.1 ** 0.05 *** 0.01) cells (b(star fmt(%9.3f)) se (par(( )) fmt(%9.3f)))  stats(N r2_b  r2_w r2_o p, fmt(%4.0f %4.3f %4.3f %6.3f)) keep(pdd9_vill    $xlist  pdd9_mean_vill sum_vill _cons)


********************************************************************************
*                                Table S8                                      *
********************************************************************************
eststo clear
xtreg hdd9  pdd9_town sum_town  $xlist  pdd9_mean_town i.country i.year   , cluster(HHID_panel) 
eststo est1

xtreg hdd9  pdd9_town sum_town  $xlist  pdd9_mean_town $year_ETHIOPIA if country==3, cluster(HHID_panel) 
eststo est2

xtreg hdd9  pdd9_town sum_town  $xlist  pdd9_mean_town $year_MALAWI  if country==6, cluster(HHID_panel) 
eststo est3

xtreg hdd9 pdd9_town sum_town  $xlist  pdd9_mean_town $year_NIGER if country==1, cluster(HHID_panel) 
eststo est4


xtreg hdd9  pdd9_town sum_town  $xlist  pdd9_mean_town $year_NIGERIA if country==2, cluster(HHID_panel) 
eststo est5


xtreg hdd9  pdd9_town sum_town  $xlist  pdd9_mean_town $year_TANZANIA if country==5, cluster(HHID_panel) 
eststo est6


xtreg hdd9  pdd9_town sum_town  $xlist  pdd9_mean_town $year_UGANDA if country==4, cluster(HHID_panel) 
eststo est7
esttab using  S8.rtf, se replace star(* 0.1 ** 0.05 *** 0.01) cells (b(star fmt(%9.3f)) se (par(( )) fmt(%9.3f)))  stats(N r2_b  r2_w r2_o p, fmt(%4.0f %4.3f %4.3f %6.3f)) keep(pdd9_town    $xlist  pdd9_mean_town sum_town _cons)


********************************************************************************
*                                Table S9                                      *
********************************************************************************
eststo clear
xtreg hdd9  pdd9_dist  sum_dist  $xlist pdd9_mean_dist i.country i.year   , cluster(HHID_panel) 
eststo est1

xtreg hdd9  pdd9_dist  sum_dist  $xlist pdd9_mean_dist $year_ETHIOPIA if country==3, cluster(HHID_panel) 
eststo est2

xtreg hdd9  pdd9_dist  sum_dist  $xlist pdd9_mean_dist $year_MALAWI  if country==6, cluster(HHID_panel) 
eststo est3

xtreg hdd9 pdd9_dist  sum_dist  $xlist pdd9_mean_dist $year_NIGER if country==1, cluster(HHID_panel) 
eststo est4


xtreg hdd9  pdd9_dist  sum_dist  $xlist pdd9_mean_dist $year_NIGERIA if country==2, cluster(HHID_panel) 
eststo est5


xtreg hdd9  pdd9_dist  sum_dist  $xlist pdd9_mean_dist $year_TANZANIA if country==5, cluster(HHID_panel) 
eststo est6


xtreg hdd9  pdd9_dist  sum_dist  $xlist pdd9_mean_dist $year_UGANDA if country==4, cluster(HHID_panel) 
eststo est7
esttab using  S9.rtf, se replace star(* 0.1 ** 0.05 *** 0.01) cells (b(star fmt(%9.3f)) se (par(( )) fmt(%9.3f)))  stats(N r2_b  r2_w r2_o p, fmt(%4.0f %4.3f %4.3f %6.3f)) keep(pdd9_dist    $xlist  pdd9_mean_dist sum_dist _cons)
restore


********************************************************************************
*                                Table S19                                     *
********************************************************************************
preserve
mat Y = J(100,5,.)
local tt "   hhsize dependent_share head_age female_head head_read  motobike phone  electricity wagejob enterprise weather_shock  plot_area other_crop dist_popcenter"

local g 1
foreach var of varlist `tt'  {
ttest `var'=0
mat Y[`g',1] = r(mu_1)
mat Y[`g',2] = r(sd_1)
local g=`g'+1

}

matrix rownames Y =  hhsize dependent_share head_age female_head head_read  motobike phone  electricity wagejob enterprise weather_shock  plot_area other_crop dist_popcenter

matrix colnames Y =  mean sd

matrix list Y
frmttable using S19.doc, replace  statmat(Y) ctitle("", "mean", "sd") sdec(2)
restore
log close






